<!-- 课程详情 -->
<template>
	<view class="content">
		<view class="nav">
			<view class="nav_item" v-for="(value,index) in navList" :key="index" @click="gotoitem(index)">
				<view class="nav_item_top">{{value.name}}</view>
				<view class="nav_item_bottom">
					<view v-if="index==0">{{value.lable}}</view>
					<view class="left" v-if="index!=0">{{value.num}}</view>
					<view class="rigth" v-if="index!=0">{{value.lable}}</view>
				</view>
			</view>
		</view>
		<!-- 列表 -->
		<view class="list">
			<view class="item" v-for="(item,index) in dataList" :key="index">
				<view class="itme_left">
					<view class="head_img">
						<image :src="item.headPhoto" :data-src="url"></image>
					</view>
					<view class="text">
						<view class="name">{{item.userName}}</view>
						<view class="label">
							<view class="label_time">{{item.dynamicsTime | getReply}}</view>
							<view class="label_text" v-if="item.userType==2&&item.typeId==1" style="color:#FF9900;">向你发出问答</view>
							<view class="label_text" v-if="item.userType==2&&item.typeId==2">回答了你的问题</view>
							<view class="label_text" v-if="item.userType==1&&item.typeId==2">你回答了老师的问题</view>
							<view class="label_text" v-if="item.userType==2&&item.typeId==4">对你进行了课堂评价</view>
							<view class="label_text" v-if="item.userType==1&&item.typeId==1">你对老师发起问答</view>
						</view>
					</view>
				</view>
				<view class="item_right">
					<i class="iconfont iconwenti1" v-if="item.userType==2&&item.typeId==4"></i>
					<i class="iconfont iconwenti1" v-else></i>
				</view>
			</view>

		</view>
		<!-- 列表为空时 -->
		<view class="not_data" v-if="dataList.length==0">
			<i class="iconfont iconwuwenjianwubiji"></i>
			<view class="not_data_text">暂还没问题~</view>
		</view>
		<!-- 消息 -->
		<navigator :url="'essayreply?courseKey='+courseKey" class="news">
			<i class="iconfont iconwenti1"></i>
		</navigator>

	</view>

</template>

<script>
	export default {
		data() {
			return {
				navList: [{
						name: '评价',
						num: 0,
						lable: '次',
					},
					// {
					// 	name: '抢答',
					// 	num: 0,
					// 	lable: '次',
					// },
					{
						name: '问答',
						num: 0,
						lable: '题',
					},
					{
						name: '练习',
						num: 0,
						lable: '题',
					},
					{
						name: '资源',
						num: 0,
						lable: '条',
					}
				],
				url: this.defimg,
				courseKey: '',
				userInfo: '',
				dataList: [],
				groupid: '',
				startTime: '',
				endTime: '',
				isArrive:''
			}
		},
		onNavigationBarButtonTap(e) {
			console.log(e);
			if (e.index == 0) {

			} else if (e.index == 1) { // 跳转笔记
				uni.showLoading({
					title: '加载中...'
				})
			}
		},
		onLoad(e) {
			console.log(e);
			this.courseKey = e.courseKey;
			this.startTime = e.startTime;
			this.endTime = e.endTime;
			this.groupid = e.groupid;
			this.isArrive=e.isArrive;
			this.userInfo = uni.getStorageSync('userInfo');
			if (this.isArrive) {
				var data = {
					stuId: this.userInfo.id,
					courseKey: this.courseKey,
					userName: this.userInfo.nicheng,
					headPhoto: this.userInfo.avatar,
					reqMethod: 2
				};
				this.$capi.apiPost('arrive/insertArrive', data).then(res => {
					if (res.data.code == 200) {
						this.isArrive=false;
						console.log('签到成功');
					}
				});
			}
			this.$on('new_note', (data) => {
				this.getList();
			});
		},
		onShow() {
			this.getList();
		},
		onUnload() {
			this.$off('new_note');
		},
		methods: {
			getList: function() {
				var data = {
					stuId: this.userInfo.id,
					courseKey: this.courseKey,
					reqMethod: 2
				}
				this.$capi.apiPost('dynamics/selDynamicsForStu', data).then(res => {
					var Data = res.data;
					console.log(Data);
					if (Data.code == 200) {
						this.dataList = Data.data.dynamics;
						this.navList[0]['lable'] = Data.data.evalName;
						this.navList[1]['num'] = Data.data.answerCount;
						this.navList[2]['num'] = Data.data.stuPractice;
						this.navList[3]['num'] = Data.data.resourceCount;
					} else {
						uni.showToast({
							title: Data.msg,
							icon: 'none'
						});
					}
				});

			},
			gotoitem(index) {
				switch (index) {
					case 0:
						uni.navigateTo({
							url: 'courseevaluate?courseKey=' + this.courseKey
						});
						break;
						// case 1:
						// 	break;
					case 1:
						uni.navigateTo({
							url: 'courseessay?courseKey=' + this.courseKey
						});
						break;
					case 2:
						uni.navigateTo({
							url: 'practise?courseKey=' + this.courseKey + '&groupid=' + this.groupid + '&startTime=' + this.startTime +
								'&endTime=' + this.endTime
						});
						break;
					case 3:
						uni.navigateTo({
							url: 'resources_list?courseKey=' + this.courseKey
						});
						break;
					default:
						break;
				}
			}
		},
		
		filters: {
			// 从返回过来的创建时间后面的时间来作为回复时间
			getReply(value) {
				return value.match(/\d+:\d+/g).toString()
			}
		}

	}
</script>

<style lang="scss">
	.content {
		position: absolute;
		width: 100%;
		height: 100%;
		background: rgba(250, 250, 250, 1);
	}

	.nav {
		width: 100%;
		height: 120upx;
		background: rgba(0, 213, 162, 1);
		display: flex;
		justify-content: space-between;
		position: fixed;
		z-index: 999;

		.nav_item {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			margin: auto;

			.nav_item_top {
				color: #FFFFFF;
				font-size: 32upx;
			}

			.nav_item_bottom {
				color: #FFFFFF;
				display: flex;
				justify-content: center;

				.left {
					font-size: 32upx;
				}

				.rigth {
					font-size: 24upx;
					margin-left: 3upx;
					padding-top: 10upx;
				}
			}
		}
	}

	.item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 92%;
		height: 140upx;
		margin: auto;
		margin-top: 20upx;
		background: rgba(255, 255, 255, 1);
		box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.06);
		border-radius: 16upx;

		.itme_left {
			display: flex;
			justify-content: flex-start;

			.head_img {
				width: 88upx;
				height: 88upx;
				margin-left: 26upx;

				image {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}
			}

			.text {
				display: flex;
				flex-direction: column;
				margin-left: 15upx;

				.name {
					color: #333333;
					font-size: 34upx;
				}

				.label {
					display: flex;
					justify-content: flex-start;

					.label_time {
						color: #999999;
						font-size: 26upx;
						margin-right: 10upx;
					}

					.label_text {
						color: #00D5A2;
						font-size: 26upx;
					}
				}
			}

		}

		.item_right {
			i {
				font-size: 50upx;
				margin-right: 40upx;
				color: rgba(0, 213, 162, 1);
			}
		}
	}

	.item:last-child {
		margin-bottom: 50upx !important;
	}

	.news {
		position: fixed;
		right: 48upx;
		bottom: 62upx;
		width: 100upx;
		height: 100upx;
		border-radius: 50%;
		background: linear-gradient(317deg, rgba(104, 229, 131, 1) 0%, rgba(32, 204, 157, 1) 100%);
		box-shadow: 0px 4px 14px rgba(14, 155, 111, 0.48);
		text-align: center;
		line-height: 100upx;

		i {
			color: #FFFFFF;
			font-size: 60upx;
		}
	}

	.not_data {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;

		i {
			margin-top: 270upx;
			font-size: 370upx;
			line-height: 340upx;
			color: rgba(194, 194, 194, 1);
		}

		.not_data_text {
			color: #999999;
			font-size: 42upx;
			line-height: 40upx;
			margin-top: 15upx;
			margin-left: 25upx;
		}

	}

	.list {
		position: relative;
		top: 120upx;
	}
</style>
